package com.ymatou.iapi.livebuyer.testcase;

import java.util.Map;




import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.livebuyer.parameter.IsSubscribeBean;
import com.ymatou.iapi.livebuyer.parameter.SubscribeBean;
import com.ymatou.iapi.livebuyer.parameter.UnSubscribeBean;
import com.ymatou.iapi.livebuyer.service.IsSubscribeCall;
import com.ymatou.iapi.livebuyer.service.SubscribeCall;
import com.ymatou.iapi.livebuyer.service.UnSubscribeCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
/**
*查询是否订阅直播
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_IsSubscribe{
	private static IsSubscribeBean issubscribeBean;
	private static IsSubscribeCall issubscribeCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询是否订阅直播");
	}

	@Before
	public void caseUp() {
		issubscribeBean=new IsSubscribeBean();
		issubscribeCall=new IsSubscribeCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(issubscribeCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_Subscribe_001() {
		Logger.start(true,"查询是否定直播订阅，成功");
		try {
			
			SubscribeBean subscribeBean = new SubscribeBean();
			SubscribeCall subscribeCall = new SubscribeCall();
			UnSubscribeBean unsubscribeBean=new UnSubscribeBean();
			UnSubscribeCall unsubscribeCall= new UnSubscribeCall();
			//创建直播订阅
			int liveid=new LiveRoomWapper().selectLastLiveRoom().getId();
			int  userId=4085;	
			subscribeBean.setLiveId(liveid);
			subscribeBean.setUserId(userId);
			subscribeCall.setData(subscribeBean);
			subscribeCall.callService();			
			Logger.verifyEquals("200", subscribeCall.getString("code"), "判断code");			
			Map m1=new LiveRoomWapper().selectLiveSubscribeById(liveid,userId).get(0);
			Logger.verifyEquals(1, Integer.parseInt(m1.get("Status").toString()),"验证Status");	
			//查询已订阅直播
			issubscribeBean.setLiveId(liveid);
			issubscribeBean.setUserId(userId);
			issubscribeCall.setData(issubscribeBean);
			issubscribeCall.callService();			
			Logger.verifyEquals("200", issubscribeCall.getString("code"), "判断code");		
			Logger.verifyEquals(true, issubscribeCall.getJsonObject().get("data").getAsJsonObject().get("isSubscribe").getAsBoolean(), "判断isSubscribe");	
			Map m2=new LiveRoomWapper().selectLiveSubscribeById(liveid,userId).get(0);
			Logger.verifyEquals(1, Integer.parseInt(m2.get("Status").toString()),"验证Status");	
			
			//取消直播订阅
			unsubscribeBean.setLiveId(liveid);
			unsubscribeBean.setUserId(userId);
			unsubscribeCall.setData(unsubscribeBean);
			unsubscribeCall.callService();			
			Logger.verifyEquals("200", unsubscribeCall.getString("code"), "判断code");			
			Map m3=new LiveRoomWapper().selectLiveSubscribeById(liveid,userId).get(0);
			Logger.verifyEquals(0, Integer.parseInt(m3.get("Status").toString()),"验证Status");	
			//查询为订阅直播
			issubscribeBean.setLiveId(liveid);
			issubscribeBean.setUserId(userId);
			issubscribeCall.setData(issubscribeBean);
			issubscribeCall.callService();			
			Logger.verifyEquals("200", issubscribeCall.getString("code"), "判断code");		
			Logger.verifyEquals(false, issubscribeCall.getJsonObject().get("data").getAsJsonObject().get("isSubscribe").getAsBoolean(), "判断isSubscribe");	
			Map m4=new LiveRoomWapper().selectLiveSubscribeById(liveid,userId).get(0);
			Logger.verifyEquals(0, Integer.parseInt(m4.get("Status").toString()),"验证Status");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}